home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog 115
/
FreelogNo115-MaiJuin2013.iso
/
Internet
/
AvantBrowser
/
asetup.exe
/
_data
/
webkit
/
chrome_100_percent.pak
/
Unnamed File 000018.txt
< prev
next >
Wrap
Text File
|
2013-04-03
|
937b
|
30 lines
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function forEach(dict, f) {
for (key in dict) {
if (dict.hasOwnProperty(key))
f(key, dict[key]);
}
}
// Assuming |array_of_dictionaries| is structured like this:
// [{id: 1, ... }, {id: 2, ...}, ...], you can use
// lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2.
function lookup(array_of_dictionaries, field, value) {
var filter = function (dict) {return dict[field] == value;};
var matches = array_of_dictionaries.filter(filter);
if (matches.length == 0) {
return undefined;
} else if (matches.length == 1) {
return matches[0]
} else {
throw new Error("Failed lookup of field '" + field + "' with value '" +
value + "'");
}
}
exports.forEach = forEach;
exports.lookup = lookup;